import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/util.dart';

showActionSheet(
    {required List<String> titles,
    int? choosedIndex,
    String? title,
    Function(int)? onTap}) {
  if (Get.context == null) {
    return;
  }
  var _query = MediaQuery.of(Get.context!);
  showModalBottomSheet(
      context: Get.context!,
      constraints: BoxConstraints.expand(
          height: titles.length * 50.r + _query.padding.bottom + 50.r),
      builder: (context) {
        return ClipRRect(
          borderRadius: BorderRadius.circular(10.r),
          child: Column(
            children: [
              title == null
                  ? const SizedBox()
                  : Container(
                      height: 50.r,
                      alignment: Alignment.center,
                      child: Text(
                        title,
                        style:
                            pfSCStyle(color: ColorsUtil.title, fontSize: 16.sp),
                      ),
                    ),
              Expanded(
                child: ListView(
                  children: titles
                      .asMap()
                      .map(
                        (key, value) => MapEntry(
                          key,
                          GestureDetector(
                            onTap: () {
                              Navigator.of(context).pop();
                              if (onTap != null) {
                                onTap(key);
                              }
                            },
                            child: Container(
                              height: 50.r,
                              width: double.infinity,
                              decoration: const BoxDecoration(
                                  border: Border(
                                      bottom: BorderSide(
                                          color: Color(0xffeeeeee), width: 1))),
                              alignment: Alignment.center,
                              child: Text(
                                value,
                                style: TextStyle(
                                    color: choosedIndex == key
                                        ? ColorsUtil.red
                                        : const Color(0xff333333),
                                    fontSize: 14.sp),
                              ),
                            ),
                          ),
                        ),
                      )
                      .values
                      .toList(),
                ),
              )
            ],
          ),
        );
      });
}
